package everydayGrade.t3;

import java.util.HashMap;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.TreeMap;

/**
 * @Author: Siantar
 * @Date: 2023-10-08-15:37
 * @Description: 1.0
 */
public class T2034 {
    class StockPrice {
        int lastTime;
        HashMap<Integer, Integer> timePriceMap;
        TreeMap<Integer, Integer> priceCntMap;

        public StockPrice() {
            lastTime = 0;
            timePriceMap = new HashMap<>();
            priceCntMap = new TreeMap<>();
        }

        public void update(int timestamp, int price) {
            if (lastTime < timestamp) lastTime = timestamp;
            int prePrice = timePriceMap.getOrDefault(timestamp, 0);
            timePriceMap.put(timestamp, price);
            if (prePrice > 0) {
                int preCnt = priceCntMap.get(prePrice);
                if (preCnt > 1) {
                    priceCntMap.put(prePrice, preCnt - 1);
                } else {
                    priceCntMap.remove(prePrice);
                }
            }
            priceCntMap.put(price,priceCntMap.getOrDefault(price,0)+1);
        }

        public int current() {
            return timePriceMap.get(lastTime);
        }

        public int maximum() {
            return priceCntMap.lastKey();
        }

        public int minimum() {
            return priceCntMap.firstKey();
        }
    }
}
